#include <windows.h>
#include <stdio.h>

#include "net_file.h"


int test_mp3m4a()
{
    const char* url = "https://zhijiajiqiren-1317543512.cos.ap-guangzhou.myqcloud.com/NpiYatHcrdQPYtpJ3nAr/resource/test/test_01.m4a";

    NetFile* netFile = net_fopen(url, "r");
    if (netFile == NULL) {
        printf("Failed to open URL.\n");
        return 1;
    }

    // 打开本地文件用于写入
    FILE* localFile = fopen("test_01.m4a", "wb");
    if (!localFile) {
        printf("Failed to open local file for writing.\n");
        net_fclose(netFile);
        return 1;
    }

    char buffer[1024];
    size_t bytesRead;
    while ((bytesRead = net_fread(buffer, 1, sizeof(buffer), netFile)) > 0) {
        fwrite(buffer, 1, bytesRead, localFile);
    }

    fclose(localFile);
    net_fclose(netFile);

    printf("File downloaded successfully.\n");
    return 0;

}
